'''
Created on Dec 7, 2011

@author: ibrahimelfar
'''
'''
Created on Dec 7, 2011

@author: ibrahimelfar
'''

import django.template
from listen.commands import VoiceCommand

class Template:
    def __init__(self, language, context, name, content):
        self.language = language
        self.context = context
        self.name = name
        self.content = content

class Action(VoiceCommand, Template):
    def __init__(self, application, utterances, steps, language, context, name, content):
        Template.__init__(self, language, context, name, content)
        VoiceCommand.__init__(self, application, utterances, steps)
        

class ActionPattern:
    def __init__(self, application, utterances, steps, contexts, name, content):
        self.application = application
        self.utterances = utterances
        self.steps = steps

        self.contexts = contexts
        self.name = name
        self.content = content


class SnippetPattern:
    def __init__(self, contexts, name, content):
        self.contexts = contexts
        self.name = name
        self.content = content

    def generate_templates(self):
        return []

DJANGO_TEMPLATE = django.template.Template('''
<templates>
{% for template in templates %}
    <template name = "template.name" template.context>
        template.content
    </template>
{% endfor %}
</templates>
''')

def serialize_templates_to_string(eclipse_templates):
    context = django.template.Context(dict(templates = eclipse_templates))
    return DJANGO_TEMPLATE.render(context)

def serialize_templates_to_file(eclipse_templates, output_file):
    output_file.write(serialize_templates_to_string(eclipse_templates))
    pass
